#include <iostream>
#include "include/nfa.h"
#include "include/dfa.h"
#include "include/debug.h"
using namespace std;

vector<vector<int>> dfaStateTable;
vector<int> dfaToken;
int main()
{
    // ========= 避免终端输出乱码 =========
    system("chcp 65001");

    // ========= NFA建图 ==========
    try
    {
        vector<Pattern> patterns = {
            // 必须按优先级排序：浮点 > 整数，复杂运算符 > 简单运算符
            {FLOAT, R"([0-9]+\.[0-9]+)"},
            {INT, R"([0-9]+)"},
            {IDN, R"([A-Za-z_][A-Za-z0-9_]*)"}, // IDN和KW统一匹配
            {OP, R"(==|<=|>=|!=|&&|\|\||[+\-*/%<>=])"},
            {SE, R"([\(\)\{\};,])"}};

        stack<NFA *> nfaLists;
        for (const auto &[type, regex] : patterns)
        {
            vector<string> result = shunt(regex);
            for (string &s : result)
            {
                cout << s << " ";
            }
            NFA *a = compile(type, result);
            nfaLists.push(a);
            // cout << a->type << " ";
            // cout << endl;
        }
        NFA *maga_nfa = merge_nfas(nfaLists);
        TranverseAndNameNfa(*maga_nfa);
    }
    catch (const exception &e)
    {
        cerr << e.what() << endl;
        system("pause");
        return EXIT_FAILURE;
    }
    // TODO：NFA确定化
    return EXIT_SUCCESS;
}
